package com.linwen.excise.niuke._20;

import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

/**
 * @author wlw
 * @date 2023/3/2 10:15 PM
 */
public class _8合并表记录 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] arr = new int[n][2];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 2; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }
        Map<Integer,Integer> treeMap = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            if(treeMap.containsKey(arr[i][0])){
                treeMap.put(arr[i][0], treeMap.get(arr[i][0])+arr[i][1]);
            }else{
                treeMap.put(arr[i][0],arr[i][1]);
            }
        }
        treeMap.forEach((k,v)->{
            System.out.println(k+" "+v);
        });
    }
}
